package Opgave10_1;

/*
* Kan tage tid - kald void start() for at starte timeren.
* Kald double stop() for at stoppe og afl�se timeren().
* Returnerer tiden i sekunder (som kommatal).
*/
public class Timer{
	private static long startedAt;
	private static boolean running = false;
	public static void start(){
		if( running ){
			throw new IllegalStateException( "Cannot call start() twice without calling stop() first" );
		}
		running = true;
		startedAt = System.currentTimeMillis();
	}
	public static double stop(){
		if( ! running ){
			throw new IllegalStateException( "Cannot call stop() without calling start() first" );
		}
		running = false;
		double d = (System.currentTimeMillis() - startedAt ) / 1000.0;
		return d;
	}
	public static void main( String[] args ) throws Exception{
		Timer.start();
		Thread.sleep( (int)(10000.0 * Math.random()) );
		double tid = Timer.stop();
		System.out.println( tid );

	}
}